#include<bits/stdc++.h>
using namespace std;
int a[20],c[20],t,ans,sum,n;
int col[20];
void upd(){
    col[n]++;
    for(int i=n;i>=1;i--){
        if(col[i]==2){
            col[i]=0;
            col[i-1]++;
        }
    }

}
void solve(){
    cin>>n;
    for(int i=1;i<=n;i++)cin>>a[i];
    memset(c,0,sizeof(c));
    memset(col,0,sizeof(col));
    for(int i=2;i<=n;i++){
        for(int j=i-1;j>=1;j--){
            if(col[i]==col[j]){
                if(a[i]==a[j]){
                    c[i]=a[i];
                    j=0;
                }
                else c[i]=0;
            }
        }
    }
    for(int i=1;i<=n;i++){
        //cout<<c[i]<<" ";
        sum+=c[i];
        ans=max(ans,sum);
        //cout<<ans<<" ";
    }
    int f=1;
    for(int i=1;i<=n;i++){
        //cout<<col[i]<<"  ";
        if(col[i]==0)f=0;
    }
    if(f==1){
        cout<<ans<<endl;
        return;
    }
    upd();
}

int main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    cin>>t;
    while(t--)solve();
    return 0;
}
